package component.renderers
{
	import mx.containers.Canvas;
	import mx.controls.Label;
	import mx.controls.advancedDataGridClasses.AdvancedDataGridListData;
	import mx.controls.listClasses.BaseListData;
	import mx.controls.listClasses.IDropInListItemRenderer;
	import mx.events.FlexEvent;
	
	import vo.ArmoryBean;

	public class RendererLabel extends Canvas implements IDropInListItemRenderer
	{
		private var _label:Label;

		public function RendererLabel()
		{
			super();

			super.horizontalScrollPolicy = "false";
			super.verticalScrollPolicy = "false";
			
			_label = new Label();
			this.addChild(_label);

			this.addEventListener(FlexEvent.UPDATE_COMPLETE, updateCompleteHandler);
		}

		private function updateCompleteHandler(event:FlexEvent):void
		{
			_label.x = (this.width - _label.width) / 2;
			_label.y = (this.height - _label.height) / 2;
		}
		private var _dataFields:Array;

		public function set dataFields(data:String):void
		{
			_dataFields = data.split(".");
		}

		private var _itemPropertyBean:ArmoryBean;

		private var _listData:AdvancedDataGridListData;

		public function set listData(value:BaseListData):void
		{
			// 拖拽时
			if((value as AdvancedDataGridListData).item == null)
				return;

			_listData = value as AdvancedDataGridListData;

			_itemPropertyBean = _listData.item as ArmoryBean;

			var temp:Object = _itemPropertyBean;
			for each(var field:String in _dataFields)
			{
				temp = temp[field];
			}
			_label.text = temp as String;
		}

		public function get listData():BaseListData
		{
			return _listData;
		}
	}
}
